home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
DB_CLIPP
/
0411.ZIP
/
TGIMAGE.C
< prev
next >
Wrap
Text File
|
1985-10-04
|
6KB
|
259 lines
/*
* Program to accept from the command line the mnemonic - up to 2
* chars - of the micro in use.
*
* This string is then married with the system date in ddmmyy format to
* produce an 8 character string which is the file name into which or
* from which an image of the hard disk will be copied/restored.
*
*/
#include "stdio.h"
main(argc,argv)
int argc;
char *argv[];
{
int c,
cntr,
dmm,
ddd,
dyy,
outfile;
char date[9],
month[4],
fr[3],
to[3],
temp,
sysid[3],
datfile[12],
errmsg[80],
cmd[27];
/*
* Set the name of the file to contain the image commands.
*/
strcpy(datfile,"TGIMAGE.DAT");
/*
* Check for a request for syntax information.
*/
if (argv[1][0] == '?')
{
puts("\n");
puts("Syntax: TGIMAGE <machine sysid> <from id> <to id> [<date>]\n");
puts("where <machine sysid> is a string of up to 2 chars\n");
puts(" <from id> is a device id (eg c: or 0:)\n");
puts(" <to id> is a device id (eg 0: or c:)\n");
puts(" <date> is a date in ddmmyy format\n");
puts(" NB if this parameter is not\n");
puts(" supplied, today's date is used\n");
puts("\n");
puts("These values are manipulated to produce a TEX command\n");
puts("such that an IMAGE from the <from id> will be made\n");
puts("to the <to id> using a filename of format \n");
puts(" <machine sysid><date>.IMG\n");
unlink(datfile);
exit(0);
}
/*
* Check for a request for version information.
*/
if (argv[1][0] == '#')
{
puts("\n");
puts("PROGRAM: TGIMAGE\n");
puts("Author: Peter Townsend\n");
puts("Date: 04Oct85\n");
puts("Version: 1.0\n");
unlink(datfile);
exit(0);
}
if ((outfile = creat(datfile)) == -1)
{
strcpy(errmsg,"Cannot create output file");
tgexit(errmsg,outfile,datfile);
}
/*
* Check number and value of parameters
*/
if (argc == 1)
{
strcpy(errmsg,"System mnemonic ommitted from command line.");
tgexit(errmsg,outfile,datfile);
}
if (!isalnum(argv[1][0]))
{
strcpy(errmsg,"Sorry...mnemonic characters must be alphanumeric");
tgexit(errmsg,outfile,datfile);
}
if (strlen(argv[1]) > 1)
{
if (!isalnum(argv[1][1]))
{
strcpy(errmsg,"Sorry...mnemonic characters must be alphanumeric");
tgexit(errmsg,outfile,datfile);
}
}
if (argc == 2)
{
strcpy(errmsg,"FROM drive ommitted from command line");
tgexit(errmsg,outfile,datfile);
}
if (!isalnum(argv[2][0]))
{
strcpy(errmsg,"Invalid FROM specification");
tgexit(errmsg,outfile,datfile);
}
if (strlen(argv[2]) > 1)
{
if (argv[2][1] != ':')
{
strcpy(errmsg,"Invalid FROM specification");
tgexit(errmsg,outfile,datfile);
}
}
sysid[0] = argv[1][0];
if (strlen(argv[1]) > 1)
{
sysid[1] = argv[1][1];
}
else
{
sysid[1] = 'x';
}
sysid[2] = '\0';
fr[0] = argv[2][0];
fr[1] = ':';
fr[2] = '\0';
if (argc == 3)
{
strcpy(errmsg,"TO drive ommitted from command line");
tgexit(errmsg,outfile,datfile);
}
if (!isalnum(argv[3][0]))
{
strcpy(errmsg,"Invalid TO specification");
tgexit(errmsg,outfile,datfile);
}
if (strlen(argv[3]) > 1)
{
if (argv[3][1] != ':')
{
strcpy(errmsg,"Invalid TO specification");
tgexit(errmsg,outfile,datfile);
}
}
to[0] = argv[3][0];
to[1] = ':';
to[2] = '\0';
if (isdigit(fr[0]))
{
if (isdigit(to[0]))
{
strcpy(errmsg,"Cannot image FROM tape TO tape");
tgexit(errmsg,outfile,datfile);
}
else
{
if (((tolower(to[0]) - 'a') < 0) || ((tolower(to[0]) - 'p') > 0))
{
strcpy(errmsg,"Invalid disk id");
tgexit(errmsg,outfile,datfile);
}
}
if (fr[0] > '5')
{
strcpy(errmsg,"Invalid tape no");
tgexit(errmsg,outfile,datfile);
}
}
if (isalpha(fr[0]))
{
if (isalpha(to[0]))
{
strcpy(errmsg,"Cannot image FROM disk TO disk");
tgexit(errmsg,outfile,datfile);
}
else
{
if (to[0] > '5')
{
strcpy(errmsg,"Invalid tape no");
tgexit(errmsg,outfile,datfile);
}
}
if (((tolower(fr[0]) - 'a') < 0) || ((tolower(fr[0]) - 'p') > 0))
{
strcpy(errmsg,"Invalid disk id");
tgexit(errmsg,outfile,datfile);
}
}
/*
* If the date has been ommitted from the command line,
* use today's date.
*/
if (argc < 5)
{
dates(date);
sscanf(date,"%2d %c %2d %c %2d",&dmm,&temp,&ddd,&temp,&dyy);
}
else
{
if (strlen(argv[4]) < 6)
{
strcpy(errmsg,"Invalid date value");
tgexit(errmsg,outfile,datfile);
}
for(cntr=0;cntr<6;cntr++)
{
if (!isdigit(argv[4][cntr]))
{
strcpy(errmsg,"Invalid date value");
tgexit(errmsg,outfile,datfile);
}
}
ddd = (atoi(argv[4][0])*10) + atoi(argv[4][1]);
dmm = (atoi(argv[4][2])*10) + atoi(argv[4][3]);
dyy = (atoi(argv[4][4])*10) + atoi(argv[4][5]);
}
/*
* Form the values into the TEX command string.
*/
if (isdigit(fr[0]))
{
sprintf(cmd,"image %2s%2s%2d%2d%2d.img %2s!!y",fr,sysid,ddd,dmm,dyy,to);
/*
* Check that the date does not include blanks in place of zeroes.
*/
for(cntr=10;cntr<16;cntr++)
{
if (cmd[cntr] == ' ')
{
cmd[cntr] = '0';
}
}
}
else
{
sprintf(cmd,"image %2s %2s%2s%2d%2d%2d.img!!y",fr,to,sysid,ddd,dmm,dyy);
/*
* Check that the date does not include blanks in place of zeroes.
*/
for(cntr=13;cntr<19;cntr++)
{
if (cmd[cntr] == ' ')
{
cmd[cntr] = '0';
}
}
}
/*
* 3rd last character is a CR, to have the command input to TEX.
*/
cmd[23] = 0xd;
/*
* 2nd last character is a ^C, to break out of TEX.
*/
cmd[24] = 0x3;
fprintf(outfile,"%24s",cmd);
fclose(outfile);
exit(0);
}